<template>
    <div>
<h1>登录页面</h1>
<table class="table table-bordered">
    <tbody>
        <tr>
            <td align="right">账号</td>
            <td><input type="text" v-model="login.userName"/></td>
        </tr>
        <tr>
            <td align="right">密码</td>
            <td><input type="password" v-model="login.userpwd"/></td>
        </tr>
        <tr>
            <td align="right"></td>
            <td><input type="button" value="登录" class="btn btn-primary" @click="logins"/></td>
        </tr>
    </tbody>
</table>

    </div>
</template>

<script setup lang="ts">
import{ref,reactive}from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import{useUserStore}from '../stores/user'
const router=useRouter();

const userStore=useUserStore();

let login=reactive({
    userName:'',
    userpwd:''
})


const logins=()=>{
    //1.判断有效性
    if(login.userName=="")
    {
       alert("账号不能为空");
       return; 
    }
    if(login.userpwd=="")
    {
       alert("密码不能为空");
       return; 
    }
    //2.发送网络请求去后段验证账号和密码在数据库中是否存在
    axios({
    method: 'get',
    url: '/api/Admin/AdminLogin',
    params: login,
  })
    .then((res) => {
      console.log(res);
      if(res.data==-1)
      {
        alert("账号不存在");
        return;
      }
      if(res.data==-2)
      {
        alert("密码错误");
        return;
      }
      alert("登录成功");
      userStore.userInfo=res.data;
      router.push("/memberlevel")
    })
    .catch((err) => {
      console.log(err);
    });
};


</script>

<style scoped>

</style>